const app = getApp(), core = require('../../utils/core');
let utils = require('../../utils/proCityCountry.js');
const util = require('../../utils/util.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    id: '',
    page:1,
    q:'',
    list:[],
    company_name:'',
    array: ['全部','男', '女'],
    index: '',
    date: '',
    status: '',
    statusList:[{id:'',name:'全部'},{id:1,name:'未到面'},{id:2,name:'未录取'},{id:3,name:'已录取'},{id:4,name:'已入职'}],
    statusList2:[{id:1,name:'未到面'},{id:2,name:'未录取'},{id:3,name:'已录取'},{id:4,name:'已入职'}],
    statusText:'状态',
  },
  bindPickerChange: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({index: e.detail.value, page:1, list:[]})
    this.get_registration_list()
  },
  bindDateChange: function (e) {
    console.log('picker发送选择改变，携带值为', e.detail.value)
    this.setData({ date: e.detail.value, page: 1, list: []})
    this.get_registration_list()
  },
  bindStatusPickerChange: function (e) {
    let items = e.detail.items;
    this.setData({status:items[0].id, statusText:items[0].name, page: 1, list: []});
    this.get_registration_list();
  },
  // 获取登记人员列表
  get_registration_list:function(){
    var that = this;
    var page = that.data.page;
    var list = that.data.list;
    var date = that.data.date;
    var sex = that.data.index;
    var company_id = app.getUserinfo(true).id;
    core.post({
      url: '/hr/get_registration_list',
      data: { page: page, date: date, sex: sex, company_id: company_id, status: this.data.status, q:this.data.q },
      success(res) {
        if(res.data.list.length>0){
          for(var i = 0; i < res.data.list.length; i++){
            list.push(res.data.list[i])
            that.setData({ list:list,company_name:res.data.company_name,total:res.data.total });
          }
        }else{
          wx.showToast({
            title: res.msg,
            icon:'none'
          })
        }
      }
    })
  },


  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.get_registration_list()
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.setData({ page:1, list:[] ,date: '', index:'',sex:'',status:'',statusText:'状态'});
    this.get_registration_list()
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var page = this.data.page;
    page++;
    this.setData({ page:page })
    this.get_registration_list()
  },

  changeStatus(e) {
    let index = e.currentTarget.dataset.index;
    this.setData({idIndex: index, id: this.data.list[index].id});
  },

  bindChangeStatusPick(e) {
    let status = e.detail.items[0].id;
    core.post({
      url: 'hr/registration_status/id/'+this.data.id,
      data: {status: status},
      success: ret=> {
        this.setData({['list['+this.data.idIndex+'].status']:status});
      }
    })
  },

  inputQ(e) {
    this.setData({q: e.detail.value.trim()});
  },
  search() {
    this.setData({page: 1, list: []});
    this.get_registration_list()
  }

});
